package g;

import c.b.a.a.a;
import com.pgl.sys.ces.out.ISdkLite;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

/* compiled from: ByteString */
public class h implements Serializable, Comparable<h> {
    public static final char[] d = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    public static final h e = m(new byte[0]);
    public final byte[] a;
    public transient int b;
    public transient String c;

    public h(byte[] bArr) {
        this.a = bArr;
    }

    public static h b(String str) {
        if (str.length() % 2 == 0) {
            int length = str.length() / 2;
            byte[] bArr = new byte[length];
            for (int i = 0; i < length; i++) {
                int i2 = i * 2;
                bArr[i] = (byte) (c(str.charAt(i2 + 1)) + (c(str.charAt(i2)) << 4));
            }
            return m(bArr);
        }
        throw new IllegalArgumentException(a.D("Unexpected hex string: ", str));
    }

    public static int c(char c) {
        if (c >= '0' && c <= '9') {
            return c - 48;
        }
        int i = 97;
        if (c < 'a' || c > 'f') {
            i = 65;
            if (c < 'A' || c > 'F') {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Unexpected hex digit: ");
                stringBuilder.append(c);
                throw new IllegalArgumentException(stringBuilder.toString());
            }
        }
        return (c - i) + 10;
    }

    public static h e(String str) {
        if (str != null) {
            h hVar = new h(str.getBytes(b0.a));
            hVar.c = str;
            return hVar;
        }
        throw new IllegalArgumentException("s == null");
    }

    public static h m(byte... bArr) {
        if (bArr != null) {
            return new h((byte[]) bArr.clone());
        }
        throw new IllegalArgumentException("data == null");
    }

    public String a() {
        int i;
        int i2;
        byte[] bArr = this.a;
        byte[] bArr2 = d.a;
        byte[] bArr3 = new byte[(((bArr.length + 2) / 3) * 4)];
        int length = bArr.length - (bArr.length % 3);
        int i3 = 0;
        for (i = 0; i < length; i += 3) {
            int i4 = i3 + 1;
            bArr3[i3] = bArr2[(bArr[i] & ISdkLite.REGION_UNSET) >> 2];
            i3 = i4 + 1;
            i2 = i + 1;
            bArr3[i4] = bArr2[((bArr[i] & 3) << 4) | ((bArr[i2] & ISdkLite.REGION_UNSET) >> 4)];
            i4 = i3 + 1;
            i2 = i + 2;
            bArr3[i3] = bArr2[((bArr[i2] & 15) << 2) | ((bArr[i2] & ISdkLite.REGION_UNSET) >> 6)];
            i3 = i4 + 1;
            bArr3[i4] = bArr2[bArr[i2] & 63];
        }
        i = bArr.length % 3;
        if (i == 1) {
            i = i3 + 1;
            bArr3[i3] = bArr2[(bArr[length] & ISdkLite.REGION_UNSET) >> 2];
            int i5 = i + 1;
            bArr3[i] = bArr2[(bArr[length] & 3) << 4];
            int i6 = i5 + 1;
            bArr3[i5] = (byte) 61;
            bArr3[i6] = (byte) 61;
        } else if (i == 2) {
            i = i3 + 1;
            bArr3[i3] = bArr2[(bArr[length] & ISdkLite.REGION_UNSET) >> 2];
            i3 = i + 1;
            i2 = (bArr[length] & 3) << 4;
            length++;
            bArr3[i] = bArr2[((bArr[length] & ISdkLite.REGION_UNSET) >> 4) | i2];
            i = i3 + 1;
            bArr3[i3] = bArr2[(bArr[length] & 15) << 2];
            bArr3[i] = (byte) 61;
        }
        try {
            return new String(bArr3, "US-ASCII");
        } catch (UnsupportedEncodingException e) {
            throw new AssertionError(e);
        }
    }

    /* JADX WARNING: Missing block: B:6:0x0025, code skipped:
            if (r7 < r8) goto L_0x0027;
     */
    /* JADX WARNING: Missing block: B:10:0x002e, code skipped:
            if (r0 < r1) goto L_0x0027;
     */
    /* JADX WARNING: Missing block: B:13:?, code skipped:
            return -1;
     */
    /* JADX WARNING: Missing block: B:14:?, code skipped:
            return 1;
     */
    public int compareTo(java.lang.Object r10) {
        /*
        r9 = this;
        r10 = (g.h) r10;
        r0 = r9.p();
        r1 = r10.p();
        r2 = java.lang.Math.min(r0, r1);
        r3 = 0;
        r4 = 0;
    L_0x0010:
        r5 = -1;
        r6 = 1;
        if (r4 >= r2) goto L_0x002b;
    L_0x0014:
        r7 = r9.j(r4);
        r7 = r7 & 255;
        r8 = r10.j(r4);
        r8 = r8 & 255;
        if (r7 != r8) goto L_0x0025;
    L_0x0022:
        r4 = r4 + 1;
        goto L_0x0010;
    L_0x0025:
        if (r7 >= r8) goto L_0x0029;
    L_0x0027:
        r3 = -1;
        goto L_0x0031;
    L_0x0029:
        r3 = 1;
        goto L_0x0031;
    L_0x002b:
        if (r0 != r1) goto L_0x002e;
    L_0x002d:
        goto L_0x0031;
    L_0x002e:
        if (r0 >= r1) goto L_0x0029;
    L_0x0030:
        goto L_0x0027;
    L_0x0031:
        return r3;
        */
        throw new UnsupportedOperationException("Method not decompiled: g.h.compareTo(java.lang.Object):int");
    }

    public final h d(String str) {
        try {
            return m(MessageDigest.getInstance(str).digest(this.a));
        } catch (NoSuchAlgorithmException e) {
            throw new AssertionError(e);
        }
    }

    /* JADX WARNING: Missing block: B:8:0x0019, code skipped:
            if (r6.o(0, r3, 0, r3.length) != false) goto L_0x001d;
     */
    public boolean equals(java.lang.Object r6) {
        /*
        r5 = this;
        r0 = 1;
        if (r6 != r5) goto L_0x0004;
    L_0x0003:
        return r0;
    L_0x0004:
        r1 = r6 instanceof g.h;
        r2 = 0;
        if (r1 == 0) goto L_0x001c;
    L_0x0009:
        r6 = (g.h) r6;
        r1 = r6.p();
        r3 = r5.a;
        r4 = r3.length;
        if (r1 != r4) goto L_0x001c;
    L_0x0014:
        r1 = r3.length;
        r6 = r6.o(r2, r3, r2, r1);
        if (r6 == 0) goto L_0x001c;
    L_0x001b:
        goto L_0x001d;
    L_0x001c:
        r0 = 0;
    L_0x001d:
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: g.h.equals(java.lang.Object):boolean");
    }

    public int hashCode() {
        int i = this.b;
        if (i != 0) {
            return i;
        }
        i = Arrays.hashCode(this.a);
        this.b = i;
        return i;
    }

    public byte j(int i) {
        return this.a[i];
    }

    public String k() {
        byte[] bArr = this.a;
        char[] cArr = new char[(bArr.length * 2)];
        int i = 0;
        for (byte b : bArr) {
            int i2 = i + 1;
            char[] cArr2 = d;
            cArr[i] = cArr2[(b >> 4) & 15];
            i = i2 + 1;
            cArr[i2] = cArr2[b & 15];
        }
        return new String(cArr);
    }

    public byte[] l() {
        return this.a;
    }

    public boolean n(int i, h hVar, int i2, int i3) {
        return hVar.o(i2, this.a, i, i3);
    }

    public boolean o(int i, byte[] bArr, int i2, int i3) {
        if (i >= 0) {
            byte[] bArr2 = this.a;
            if (i <= bArr2.length - i3 && i2 >= 0 && i2 <= bArr.length - i3 && b0.a(bArr2, i, bArr, i2, i3)) {
                return true;
            }
        }
        return false;
    }

    public int p() {
        return this.a.length;
    }

    public h t(int i, int i2) {
        if (i >= 0) {
            byte[] bArr = this.a;
            if (i2 <= bArr.length) {
                int i3 = i2 - i;
                if (i3 < 0) {
                    throw new IllegalArgumentException("endIndex < beginIndex");
                } else if (i == 0 && i2 == bArr.length) {
                    return this;
                } else {
                    byte[] bArr2 = new byte[i3];
                    System.arraycopy(bArr, i, bArr2, 0, i3);
                    return new h(bArr2);
                }
            }
            throw new IllegalArgumentException(a.c(a.g("endIndex > length("), this.a.length, ")"));
        }
        throw new IllegalArgumentException("beginIndex < 0");
    }

    public String toString() {
        if (this.a.length == 0) {
            return "[size=0]";
        }
        String w = w();
        int length = w.length();
        int i = 0;
        int i2 = 0;
        while (i < length) {
            if (i2 != 64) {
                int codePointAt = w.codePointAt(i);
                if ((Character.isISOControl(codePointAt) && codePointAt != 10 && codePointAt != 13) || codePointAt == 65533) {
                    i = -1;
                    break;
                }
                i2++;
                i += Character.charCount(codePointAt);
            } else {
                break;
            }
        }
        i = w.length();
        String str = "…]";
        String str2 = "[size=";
        String str3 = "]";
        StringBuilder g;
        if (i == -1) {
            if (this.a.length <= 64) {
                g = a.g("[hex=");
                g.append(k());
                g.append(str3);
                w = g.toString();
            } else {
                g = a.g(str2);
                g.append(this.a.length);
                g.append(" hex=");
                g.append(t(0, 64).k());
                g.append(str);
                w = g.toString();
            }
            return w;
        }
        String replace = w.substring(0, i).replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r");
        if (i < w.length()) {
            g = a.g(str2);
            g.append(this.a.length);
            g.append(" text=");
            g.append(replace);
            g.append(str);
            w = g.toString();
        } else {
            w = a.E("[text=", replace, str3);
        }
        return w;
    }

    public h u() {
        int i = 0;
        while (true) {
            byte[] bArr = this.a;
            if (i >= bArr.length) {
                return this;
            }
            byte b = bArr[i];
            if (b < (byte) 65 || b > (byte) 90) {
                i++;
            } else {
                bArr = (byte[]) bArr.clone();
                bArr[i] = (byte) (b + 32);
                for (int i2 = i + 1; i2 < bArr.length; i2++) {
                    byte b2 = bArr[i2];
                    if (b2 >= (byte) 65 && b2 <= (byte) 90) {
                        bArr[i2] = (byte) (b2 + 32);
                    }
                }
                return new h(bArr);
            }
        }
    }

    public byte[] v() {
        return (byte[]) this.a.clone();
    }

    public String w() {
        String str = this.c;
        if (str != null) {
            return str;
        }
        str = new String(this.a, b0.a);
        this.c = str;
        return str;
    }

    public void x(e eVar) {
        byte[] bArr = this.a;
        eVar.A0(bArr, 0, bArr.length);
    }
}
